package com.example.clock.taskPage;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.clock.R;
import com.example.clock.basicClass.Task;

import java.util.List;

public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.ViewHolder> {

    private List<Task> taskList;

    public TaskAdapter(List<Task> taskList) {
        this.taskList = taskList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.task_layout, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Task task = taskList.get(position);
//        holder.textTaskName.setText(task.getTaskName());
//        Log.v("my",holder.textTaskName.getText().toString());
//        holder.textTaskDescription.setText(task.getTaskId());
//        Log.v("my",holder.textTaskDescription.getText().toString());

        holder.taskStartTime.setText(task.getStartTime().substring(0,5));
        holder.taskEndTime.setText(task.getEndTime().substring(0,5));
        holder.textTaskName.setText(task.getTaskName());
        holder.textTaskDescription.setText(task.getTips());
        holder.taskLargeTags.setText(task.getLargeTags());
        holder.taskSmallTags.setText(task.getSmallTags());

//        holder.textTaskDescription.setText("texttest");

    }

    @Override
    public int getItemCount() {
        return taskList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView taskStartTime;
        public TextView taskEndTime;
        public TextView textTaskName;
        public TextView textTaskDescription;
        public TextView taskLargeTags;
        public TextView taskSmallTags;

        public ViewHolder(View view) {
            super(view);
            taskStartTime = view.findViewById(R.id.TaskStartTime);
            taskEndTime = view.findViewById(R.id.TaskEndTime);
            textTaskName = view.findViewById(R.id.textTaskName);
            textTaskDescription = view.findViewById(R.id.textTaskDescription);
            taskLargeTags = view.findViewById(R.id.TaskLargeTags);
            taskSmallTags = view.findViewById(R.id.TaskSmallTags);

//            textTaskDescription.setText("ee");

            Log.v("my",textTaskName.getText().toString());
            Log.v("my",textTaskDescription.getText().toString());

//            Toast toast = Toast.makeText(this /* MyActivity */, "textTaskDescription",Toast.LENGTH_SHORT);
//            toast.show();
        }
    }
}

